﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AutoDeploy.Common.Library
{
    /// <summary>
    /// Contains everything you would need to run a command by XML.  Alter at your own will. Please send updates to the contacts below. 
    /// XML Configuration Example: 
    ///    <CommandSet priority="1">
    ///    <!-- PreReq means it runs before configuration:: true/false to control the process "Stop on Error" -->
    ///    <Part>PreReq::false</Part>
    ///    <Command>Message</Command>
    ///    <Description>Shameless self promotion</Description>
	///          <Values>
    ///      	       <Value>Deployment Helper:Provided By Mark Rowe  part of the Auto-Deployer @ autodeploy.codeplex.com</Value>
    ///     	</Values>
    ///    </CommandSet>
    ///From IRDev Library Project by Mark Rowe markwrowe@hotmail.com  http://everythingworkflow.spaces.live.com  ,  Daniel Turnell daniel.turnell@gmail.com,  Daniel Turnell daniel.turnell@gmail.com
    ///This Project http://autodeploy.codeplex.com
    /// </summary>
    public class CommandSet
    {
        /// <summary>
        ///  The order in which the Command will run
        ///  In Config: <CommandSet priority="1">
        /// </summary>
        public int Priority { get; set; }
        /// <summary>
        ///  This is a Part of the string 
        ///  If the Part contains :: like so:
        ///     In Config: <Part>PreReq::false</Part>
        ///     The Part is PreReq and the PartTrigger is false
        ///  Otherwise   
        ///  <Part>Command</Part>
        ///  The Part is the complete element in configuration
        /// </summary>
        public string Part { get; set; }
        /// <summary>
        ///  This is a Part of the string 
        ///  If the Part contains :: like so:
        ///     In Config: <Part>PreReq::false</Part>
        ///     The Part is PreReq and the PartTrigger is false
        ///  Otherwise   
        ///  <Part>Command</Part>
        ///  The PartTrigger is considered empty in this configuration
        /// </summary>
        public string PartTrigger { get; set; }
        ///<summary>
        ///This is the Command the item runs through. 
         ///<Command>Message</Command>
        /// </summary>
        public string Command { get; set; }
        ///<summary>
        ///This is the Command the item runs through. 
        ///<Command>Message</Command>
        /// </summary>
        public string CommandTrigger { get; set; }

        /// <summary>
        ///  The list of Values in the current command set.
        ///  <Value>[PreparedApp::BTSTASK] AddResource -Source:C:\Projects\EDI Guidance\Main\Src\Orchestrations\bin\Debug\Microsoft.BizTalk.Samples.EDIGuidance.HelperComponents.dll  -Type:BizTalkAssembly -Options:GacNow /Overwrite</Value>
        /// </summary>
        public List<string> Values { get; set; }

        /// <summary>
        /// The Description given for the command set. 
        /// <Description>Create_EDI_Tools_GetNewInterchanges_SP.sql found at C:\projects\EDI Guidance\Main\src\Database</Description>
        /// </summary>
        public string Description { get; set; }
        
        /// <summary>
        /// <Success>Microsoft BizTalk Server 2009 Hotfix [See KB article 977428] is installed properly.</Success>
        /// If the Command Succeeds, what should the user see.
        /// </summary>
        public string Success { get; set; }

        /// <summary>
        /// If the Command Fails, what should the user see.
        ///  <Error>Microsoft BizTalk Server 2009 Hotfix [See KB article 977428] should be installed to avoid compilation errors. Link: http://support.microsoft.com/hotfix/KBHotfix.aspx?kbnum=977428&amp;kbln=en-us </Error>
        /// </summary>
        public string Error { get; set; }
        
        /// <summary>
        /// Constructor
        /// </summary>
        public CommandSet()
        {
            Priority = 0;
            Part = string.Empty;
            PartTrigger = string.Empty;
            Command = string.Empty;
            CommandTrigger = string.Empty;
            Values = new List<string>();
            Description = string.Empty;
            Success = string.Empty;
            Error = string.Empty;
        }
        /// <summary>
        /// Overridden To String 
        /// Spits out a Complete String when needed. 
        /// </summary>
        /// <param name="isShortString"></param>
        /// <returns></returns>
        public string ToString(bool isShortString)
        { 
            StringBuilder sb = new StringBuilder();
            sb.Append("Priority:"+ (isShortString ? Priority.ToString().Trim()+" |" : Priority.ToString().Trim() + "\n"));
            sb.Append("Part:"+(isShortString ? Part.ToString().Trim()+" |"  : Part.ToString().Trim() + "\n"));
            sb.Append("PartTrigger:" + (isShortString ? PartTrigger.ToString().Trim() + " |" : PartTrigger.ToString().Trim() + "\n"));
            sb.Append("Command:" + (isShortString ? Command.ToString().Trim() + " |" : Command.ToString().Trim() + "\n"));
            sb.Append("CommandTrigger:" + (isShortString ? CommandTrigger.ToString().Trim() + " |" : CommandTrigger.ToString().Trim() + "\n"));
            sb.Append("Values:" + (isShortString ? StringHelper.ListOfStringToString(Values, false) + " |" : StringHelper.ListOfStringToString(Values, true) + "\n"));
            sb.Append("Description:" + (isShortString ? Description.ToString().Trim() + " |" : Description.ToString().Trim() + "\n"));
            sb.Append("Success:" + (isShortString ? Description.ToString().Trim() + " |" : Description.ToString().Trim() + "\n"));
            return sb.ToString();
        }
    }
}
